package cc.comac.mom.util;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class BeanManager implements ApplicationContextAware{
	private static ApplicationContext applicationContext;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		BeanManager.applicationContext = applicationContext;
	}

	// 获得applicationContext
	public static ApplicationContext getApplicationContext() {
		// assertContextInjected();
		return applicationContext;
	}

	public static void clearHolder() {
		applicationContext = null;
	}

	//获取Bean
	@SuppressWarnings("hiding")
	public static <T> T getBean(Class<T> requiredType) {
		// assertContextInjected();
		return  applicationContext.getBean(requiredType);
	}

}
